home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Joystick Magazine 1995 July & August
/
cd No4 joystick No62.iso
/
mac
/
pc
/
EMULATOR
/
PC64
/
IMPORT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-28
|
2KB
|
83 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <dos.h>
#include <ctype.h>
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned int uint;
typedef unsigned long dword;
struct {
char acTag[8];
char acName[17];
byte bRecord;
} C64Header = {
"C64File"
};
int main(int argc, char** argv) {
_find_t find;
word wFind = _dos_findfirst("*.T64", _A_NORMAL, &find);
if (wFind) {
printf("There are no C64S tape files (*.T64) in this directory.\n");
} else {
while (!wFind) {
char acNew[80];
int hIn, hOut, iSize;
word wStart;
printf("%12s ", find.name);
char* pcSource = find.name;
char* pcDest = acNew;
while (*pcSource != '.') {
if (isalnum(*pcSource)) {
*pcDest++ = *pcSource;
}
pcSource++;
}
strcpy(pcDest, ".P00");
if (!_access(acNew, 0)) {
printf("skipped (target exists)\n");
goto Next;
}
hIn = _open(find.name, _O_BINARY | _O_RDONLY);
if (!hIn) goto Error;
static char acBuffer[16384];
iSize = _read(hIn, acBuffer, 1024);
if (iSize == -1) goto Error;
if (iSize < 1024 || memcmp(acBuffer, "C64S tape file", 14)) {
printf("skipped (wrong format)\n");
goto Next;
}
hOut = _open(acNew, _O_BINARY | _O_CREAT | _O_TRUNC | _O_RDWR, _S_IREAD | _S_IWRITE);
if (!hOut) goto Error;
memset(C64Header.acName, 0, 16);
strcpy(C64Header.acName, acNew);
*(long*)strchr(C64Header.acName, '.') = 0;
if (_write(hOut, &C64Header, 26) != 26) goto Error;
wStart = *(word*)(acBuffer + 0x42);
if (_write(hOut, &wStart, 2) != 2) goto Error;
while (iSize) {
iSize = _read(hIn, acBuffer, 16384);
if (iSize == -1) goto Error;
if (_write(hOut, acBuffer, iSize) != iSize) goto Error;
}
if (_close(hOut)) goto Error;
if (_close(hIn)) goto Error;
printf("--> %s\n", acNew);
Next:
wFind = _dos_findnext(&find);
}
}
return 0;
Error:
perror(NULL);
return 1;
}